package jdbc;

import java.sql.DriverManager;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;

public class DBHelper {
	
	public static final String url = "jdbc:mysql://localhost:3306/test";
	public static final String className = "com.mysql.jdbc.Driver";
	public static final String user = "root";
	public static final String password = "123456";
	
	public Connection conn = null;
	public PreparedStatement pst = null;
	
	public DBHelper(String sql){
		try{
			Class.forName(className);
			conn = (Connection) DriverManager.getConnection(url,user,password);
			pst = (PreparedStatement) conn.prepareStatement(sql);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void close(){
		try{
			this.conn.close();
			this.pst.close();
		}catch(SQLException e){
			e.printStackTrace();
		}
	}

}
